#!/usr/bin/env python
# -*- coding: utf-8 -*-

from PySide import QtCore, QtGui
import clever_rc

class Map(QtGui.QLabel):
    clicked = QtCore.Signal(dict)
    def __init__(self, parent=None):
        super(Map, self).__init__(parent)
        
        self.gameMapImage = QtGui.QPixmap()
        self.pathMap = ":/images/map.png"
        self.loadMapImage()

    def loadMapImage(self):
        newImage = QtGui.QPixmap()
        if not newImage.load(self.pathMap):
            QtGui.QMessageBox.warning( \
                self, \
                "Open Image", \
                "The image file could not be loaded.", \
                QtGui.QMessageBox.Cancel)
            return
        self.gameMapImage = newImage
        self.setPixmap(newImage)

    def dragEnterEvent(self, event):
        print event.pos()
        

    def mousePressEvent(self, event):
        print self.targetSquare(event.pos())
        print self.targetCell(event.pos())
        self.clicked.emit({'square': self.targetSquare(event.pos()), 'cell': self.targetCell(event.pos())})
        
    def targetCell(self, position):
        return [position.x() // 26, position.y() // 26]

    def targetSquare(self, position):
        return QtCore.QRect(position.x() // 26 * 26, position.y() // 26 * 26, 26, 26)


